package com.xliang.spider.version04.dao.impl;

import com.xliang.spider.version04.dao.SpiderChapterDao;
import com.xliang.spider.version04.dao.impl.base.BaseDaoImpl;
import com.xliang.spider.version04.pojo.ChapterEntity;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ${DESCRIPTION}
 *
 * @author xiongl
 * @create 2016-06-21 16:23
 */
@Repository
public class SpiderChapterDaoImpl extends BaseDaoImpl implements SpiderChapterDao
{
    @Override
    public int insertChapter(ChapterEntity chapter)
        throws Exception
    {
        return getSqlSession().insert("LessonMapper.insertChapter", chapter);
    }
    
    @Override
    public int updateChapter(ChapterEntity chapter)
        throws Exception
    {
        return getSqlSession().update("LessonMapper.updateChapter", chapter);
    }

    @Override
    public int updateChapterStatusById(ChapterEntity chapter)
        throws Exception
    {
        return getSqlSession().update("LessonMapper.updateChapterStatusById", chapter);
    }

    @Override
    public List<ChapterEntity> findChapterList()
        throws Exception
    {
        return getSqlSession().selectList("LessonMapper.findChapterList");
    }
    
    @Override
    public ChapterEntity findChapterByChapterIdAndLessonName(int chapterId, String lessonName)
        throws Exception
    {
        Map<String, Object> param = new HashMap<>();
        param.put("chapterId", chapterId);
        param.put("lessonName", lessonName);
        return getSqlSession().selectOne("LessonMapper.findChapterByChapterIdAndLessonName", param);
    }
}
